package com.scau.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.scau.model.EmpProduct;
import com.scau.model.Salary;
@Component
public class EmpProductService extends BaseService<EmpProduct> {
	private SalaryService salaryService;

	@Transactional
	public void addRecord(EmpProduct empProduct) {
		this.add(empProduct);
		Salary salary=new Salary();
		Salary salarytmp=salaryService.findUniqueById(salary, "userid", empProduct.getUserid(), "date");
		if(null!=salarytmp){
			salary.setBalance(salarytmp.getBalance()+empProduct.getEarning());	
		}
		else {
			salary.setBalance(empProduct.getEarning());
		}
		salary.setUserid(empProduct.getUserid());			
		salary.setExpend(0);
		salary.setEarning(empProduct.getEarning());
		salary.setDate(new Date());
		salaryService.add(salary);
		
		
	}

	
	//***********************************************
	public SalaryService getSalaryService() {
		return salaryService;
	}

	@Resource
	public void setSalaryService(SalaryService salaryService) {
		this.salaryService = salaryService;
	}
}
